<?php

namespace app\home\controller;

use think\facade\Request;
use app\home\model\Spec_goods;
use app\home\model\Cartshop;

class Store extends Base
{
    public function storeimg()
    {
        $data = Spec_goods::select();
        $this->ok($data);
    }


    public function cartshop()
    {
        $param = Request::param();

        $data = [
            'user_id' => $param['user_id'],
            'goods_id' => $param['goods_id'],
            'num' => $param['num'],
            'sum' => $param['sum'],
            'is_se' => 1,
        ];


        if (!Cartshop::where('user_id', $param['user_id'])->where('goods_id', $param['goods_id'])->find()) {
            $res = Cartshop::insert($data);
        } else {
            $res = Cartshop::where('user_id', $param['user_id'])->where('goods_id', $param['goods_id'])->update($data);
        }

        if (!$res) {
            $this->fail('加入购物车失败');
        }
        $this->ok('加入购物车成功');
    }
}
